package br.com.cqipac.ejb;

import java.net.URL;
import java.util.List;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.xml.namespace.QName;
import javax.xml.rpc.Service;
import javax.xml.rpc.ServiceFactory;

import br.com.cqipac.to.Setor;

public class WebServiceTeste {

	public static void main(String[] args) throws Exception {
		
		
		
		
//		System.out.println("Starting Test Client");
//        URL url = new URL("http://127.0.0.1:8080/CQIpacEAR-CQIpacEJB/FacadeIpac?wsdl");
//        QName qname = new QName(
//                        "http://ejb.cqipac.com.br/",
//                        "CQIpacWS");
//
//        System.out.println("Creating a service Using: \n\t" 
//                                   + url + " \n\tand " + qname);
//        ServiceFactory factory = ServiceFactory.newInstance();
//        Service remote = factory.createService(url, qname);
//
//        System.out.println("Obtaining reference to a proxy object");
//        FacadeIpacRemote proxy = (FacadeIpacRemote) remote.getPort(FacadeIpacRemote.class);
//        System.out.println("Accessed local proxy: " + proxy);
//       
//        String string = "John";
//        System.out.println("Sending: " + string);
//        
//        System.out.println("Receiving: " + proxy.listaSetores().toString());
		
		
		
		// TODO Auto-generated method stub
		try {
			Context jndiContext = getInitialContext();

			Object ref = jndiContext.lookup("java:comp/env/service/CQIpacWS");
			FacadeIpacRemote facadeIpac = (FacadeIpacRemote) ref;
			List<Setor> setores = facadeIpac.listaSetores();

			System.out.print(setores.toString());

			// System.out.println(inclusao.getNomSetor());

			// Funcionario func = new Funcionario();
			// func.setNomFuncionario("Fulano EJB");
			// func.setDesUsuario("fulano");
			// func.setDesSenha("123");
			// func.setDtInclusao(new Date());
			// func.setFuncionario(inclusao);
			//			
			// f.persist(func);
			//			
			// System.out.println(func.getNomFuncionario());

		} catch (javax.naming.NamingException ne) {
			ne.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public static Context getInitialContext()
			throws javax.naming.NamingException {

		Properties p = new Properties();
		p.put(Context.INITIAL_CONTEXT_FACTORY,
				"org.jnp.interfaces.NamingContextFactory");
		p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
		p.put(Context.PROVIDER_URL, "localhost");
		return new InitialContext(p);
	}

}
